"use strict";
/* Controllers */
app.controller("wordsIndexController", ['$scope', '$location', '$rootScope', '$routeParams', 'wordsIndexService', function ($scope, $location, $rootScope, $routeParams, wordsIndexService) {

    var vm = $scope.vm;
    vm.p = {};

    var errorFn = function (result) {
        alert(result);
    };

    $scope.getTopWords = function () {
        var vm = $scope.vm;
        let params = {}
        var successFn = function (response) {
            var data = response.data;
            if (data == null) return;
            vm.p = data

        };
        wordsIndexService.getTopWords(params, successFn, errorFn);
    };
    $scope.getTopWords()

}]);

/* Services */
app.service('wordsIndexService', ['ajaxService', function (ajaxService) {
    this.getTopWords = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/wordTop/getTopWords.do", successFunction, errorFunction);
    };
}]);

app.filter('wordToHref', function () { //可以注入依赖
    return function (item,zpsrc) {
        console.log(item)
        if (item == null) {
            return "-";
        }

        let urlParam = {}
        urlParam.inword = item
        urlParam.aggType = 'aggByAreaName'
        console.log("urlParam" + urlParam)

        if (zpsrc == 'wuba') {
            var str = '#/star/main/wuba_words_top/' + encodeURIComponent(JSON.stringify(urlParam));
            return str;
        } else if (zpsrc == 'ganji') {
            var str = '#/star/main/ganji_words_top/' + encodeURIComponent(JSON.stringify(urlParam));
            return str;
        }
    }
});


